//
//  TouchedSprite.m
//  iSudoku
//
//  Created by acumen on 5/27/13.
//  Copyright 2013 Tri Vo. All rights reserved.
//

#import "SingleTouchSprite.h"


@implementation SingleTouchSprite

- (void)onEnter {
    [[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
    [super onEnter];
}

- (void)onExit {
    [[[CCDirector sharedDirector] touchDispatcher] removeDelegate:self];
    [super onExit];
}

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
    BOOL isTouched = [self touched:touch];
    if (isTouched) {
        [self stopAllActions];
        id enlarge = [CCScaleTo actionWithDuration:0.5f scale:1.1f];
        id resize = [CCScaleTo actionWithDuration:0.5f scale:1];
        [self runAction:[CCSequence actions:enlarge, resize, nil]];
    }
    
    return isTouched;
}

- (BOOL) touched:(UITouch *)touch {
    CGPoint touchPoint = [touch locationInView:touch.view];
    CGRect rect = [self boundingBox];
    if (CGRectContainsPoint(rect, touchPoint)) {
        return YES;
    }
    return NO;
}

@end
